import time

from custom.LDA_model import GibbsLDA
import util.PATH as PATH
import util.data_helper as data_helper
import custom.data_helper as c_data_helper

from custom.LDA_SVM import svm_main as SVM_main
from custom.LDA_KL import main as KL_main
from custom.DERTOM import main as DERTOM_main

if __name__ == '__main__':

	T = 600             # 这俩参数写在这儿是为了使"程序入口"这个概念更加名副其实, 方便调节
	n_iteration = 300
	# parser = argparse.ArgumentParser()
	# parser.add_argument('index', help='指定数据集的索引')
	# args = parser.parse_args()
	# index = int(args.index)

	print('数据集:{}'.format('DERTOM_TRUE'))
	print('')
	bug_msg_all, _ = data_helper.get_msg_all()
	vocabulary = data_helper.create_vocabulary()
	developers_list = data_helper.create_developers_list()
	time_windows = data_helper.split_dataset_by_time_windows(bug_msg_all)

	# train_time_windows = []
	for i in range(10):  # 对应10个窗口,
	# for i in [0]:  # 对应10个窗口,
		start_time = time.clock()
		print('当前正在训练第{}个窗口:'.format(i))
		j = 0
		# train_time_windows.extend(time_windows[i])
		train_time_windows = []
		while j <= i:
			train_time_windows.extend(time_windows[j])
			j += 1
		eval_time_windows = time_windows[i + 1]

		train_docs_list, train_label_list = c_data_helper.get_train_and_eval_set(vocabulary, developers_list,
		                                                                         bug_msg_all, train_time_windows)
		eval_docs_list, eval_label_list = c_data_helper.get_train_and_eval_set(vocabulary, developers_list, bug_msg_all,
		                                                                       eval_time_windows)
		DERTOM_main(i, T, n_iteration, train_docs_list, train_label_list, eval_docs_list, eval_label_list)
		print('窗口{}花费时间: {}'.format(i, time.clock() - start_time))